﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
public enum AccountType { Saving, Credit }
public struct TransactionRecord
{
    public DateTime Time;
    public decimal Amount;
    public string Description;
}


public class BadCashException : Exception
{
    public BadCashException(string message) : base(message) { }
}
public interface ICashMachine
{
    void Withdraw(Account acc, decimal amount);
}
public class BigMoneyArgs : EventArgs
{
    public Account Account { get; set; }
    public decimal Amount { get; set; }
    public BigMoneyArgs(Account account, decimal amount)
    {
        Account = account;
        Amount = amount;
    }
}
class pro
{
    static void Main()
    {
        // 创建银行对象
        Bank bank = new Bank { Name = "示例银行" };

        // 创建普通账号和信用账号，并加入银行
        Account acc1 = new Account("1001", 5000);
        CreditAccount acc2 = new CreditAccount("2002", 3000, 5000);

        bank.AddAccount(acc1);
        bank.AddAccount(acc2);

        // 创建ATM机，并注册大额取款事件
        ATM atm = new ATM();
        atm.BigMoneyFetched += (sender, e) =>
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"【告警】大额取款：账户 {e.Account.AccountId} 取款 {e.Amount:C}");
            Console.ResetColor();
        };

        // 显示当前银行账户信息
        Console.WriteLine("---- 银行账户信息 ----");
        bank.DisplayAccounts();
        Console.WriteLine();

        try
        {
            // 尝试取款操作，如果取款金额达到或超过10000，事件将被触发
            Console.WriteLine("尝试取款 12000 元...");
            atm.Withdraw(acc2, 12000);
            Console.WriteLine("取款成功！");
        }
        catch (BadCashException ex)
        {
            Console.WriteLine($"【异常】坏钞异常：{ex.Message}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"【异常】操作失败：{ex.Message}");
        }

        Console.WriteLine();
        Console.WriteLine("---- 取款后银行账户信息 ----");
        bank.DisplayAccounts();

        // 防止控制台立即关闭
        Console.WriteLine("\n按任意键退出...");
        Console.ReadKey();
    }
}